package com.ylyq.ylxx.controller;

import com.ylyq.ylxx.model.ResponseData;
import com.ylyq.ylxx.model.bean.*;
import com.ylyq.ylxx.model.request.*;
import com.ylyq.ylxx.service.IOceanengineToolService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @ClassName OceanengineToolController
 * @Description TODO
 * @Author xiaweichao
 * @Date 2020/7/13 11:38
 * @Version 1.0
 */
@RestController
@RequestMapping("/oCeanengine/tool")
@Api(description = "巨量引擎的工具信息查询相关接口")
public class OceanengineToolController {
    @Autowired
    private IOceanengineToolService iOceanengineToolService;

    @PostMapping("/getActionCategory")
    @ApiOperation(value = "行为兴趣定向行为类目查询", response = OceanengineActionCategory.class)
    public ResponseData getActionCategory(@RequestBody ActionCategoryRequest actionCategoryRequest) {
        return iOceanengineToolService.getActionCategory(actionCategoryRequest);
    }

    @PostMapping("/getActionKeyword")
    @ApiOperation(value = "行为兴趣定向行为关键词查询", response = OceanengineActionKeyword.class)
    public ResponseData getActionKeyword(@RequestBody ActionKeywordRequest actionKeywordRequest) {
        return iOceanengineToolService.getActionKeyword(actionKeywordRequest);
    }

    @GetMapping("/getInterestCategory")
    @ApiOperation(value = "兴趣类目查询", response = OceanengineInterestCategory.class)
    public ResponseData getInterestCategory(@RequestParam Long advertiser_id) {
        return iOceanengineToolService.getInterestCategory(advertiser_id);
    }

    @PostMapping("/getInterestKeyword")
    @ApiOperation(value = "兴趣关键词查询", response = OceanengineInterestKeyword.class)
    public ResponseData getInterestKeyword(@RequestBody InterestKeywordRequest actionKeywordRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanengineToolService.getInterestKeyword(actionKeywordRequest));
    }

    @PostMapping("/getCustomAudience")
    @ApiOperation(value = "获取人群包列表", response = OceanengineCustomAudience.class)
    public ResponseData getCustomAudience(@RequestBody CustomAudienceRequest customAudienceRequest) {
        return iOceanengineToolService.getCustomAudience(customAudienceRequest);
    }

    @PostMapping("/getCustomAudienceDetail")
    @ApiOperation(value = "获取人群包详细信息", response = OceanengineCustomAudienceDetail.class)
    public ResponseData getCustomAudienceDetail(@RequestBody CustomAudienceDetailRequest customAudienceRequest) {
        return iOceanengineToolService.getCustomAudienceDetail(customAudienceRequest);
    }

    @PostMapping("/publishCustomAudience")
    @ApiOperation(value = "发布人群包", response = OceanenginePublishCustomAudience.class)
    public ResponseData publishCustomAudience(@RequestBody PublishCustomAudienceRequest publishCustomAudienceRequest) {
        return iOceanengineToolService.publishCustomAudience(publishCustomAudienceRequest);
    }

    @PostMapping("/pushCustomAudience")
    @ApiOperation(value = "推送人群包", response = OceanenginePushCustomAudience.class)
    public ResponseData pushCustomAudience(@RequestBody PushCustomAudienceRequest pushCustomAudienceRequest) {
        return iOceanengineToolService.pushCustomAudience(pushCustomAudienceRequest);
    }

    @PostMapping("/deleteCustomAudience")
    @ApiOperation(value = "删除人群包", response = OceanengineDeleteCustomAudience.class)
    public ResponseData deleteCustomAudience(@RequestBody DeleteCustomAudienceRequest deleteCustomAudienceRequest) {
        return iOceanengineToolService.deleteCustomAudience(deleteCustomAudienceRequest);
    }

    @PostMapping("/lookalikeCustomAudience")
    @ApiOperation(value = "拓展人群包", response = OceanengineLookalikeCustomAudience.class)
    public ResponseData lookalikeCustomAudience(@RequestBody LookalikeCustomAudienceRequest lookalikeCustomAudienceRequest) {
        return iOceanengineToolService.lookalikeCustomAudience(lookalikeCustomAudienceRequest);
    }

    @PostMapping("/calcCustomAudience")
    @ApiOperation(value = "运算人群包", response = OceanengineCalcCustomAudience.class)
    public ResponseData calcCustomAudience(@RequestBody CalcCustomAudienceRequest calcCustomAudienceRequest) {
        return iOceanengineToolService.calcCustomAudience(calcCustomAudienceRequest);
    }

    @PostMapping("/ruleCustomAudience")
    @ApiOperation(value = "规则人群包", response = OceanengineRuleCustomAudience.class)
    public ResponseData ruleCustomAudience(@RequestBody RuleCustomAudienceRequest ruleCustomAudienceRequest) {
        return iOceanengineToolService.ruleCustomAudience(ruleCustomAudienceRequest);
    }

    @PostMapping("/getAudiencePackage")
    @ApiOperation(value = "获取定向包", response = OceanengineGetAudiencePackage.class)
    public ResponseData getAudiencePackage(@RequestBody GetAudiencePackageRequest getAudiencePackageRequest) {
        return iOceanengineToolService.getAudiencePackage(getAudiencePackageRequest);
    }

    @PostMapping("/createAudiencePackage")
    @ApiOperation(value = "创建定向包", response = OceanengineCreateAudiencePackage.class)
    public ResponseData createAudiencePackage(@RequestBody CreateAudiencePackageRequest createAudiencePackageRequest) {
        return iOceanengineToolService.createAudiencePackage(createAudiencePackageRequest);
    }

    @PostMapping("/updateAudiencePackage")
    @ApiOperation(value = "更新定向包", response = OceanengineUpdateAudiencePackage.class)
    public ResponseData updateAudiencePackage(@RequestBody UpdateAudiencePackageRequest createAudiencePackageRequest) {
        return iOceanengineToolService.updateAudiencePackage(createAudiencePackageRequest);
    }

    @PostMapping("/deleteAudiencePackage")
    @ApiOperation(value = "删除定向包", response = OceanengineDeleteAudiencePackage.class)
    public ResponseData deleteAudiencePackage(@RequestBody DeleteAudiencePackageRequest deleteAudiencePackageRequest) {
        return iOceanengineToolService.deleteAudiencePackage(deleteAudiencePackageRequest);
    }

    @PostMapping("/bindAudiencePackage")
    @ApiOperation(value = "计划绑定定向包", response = OceanengineBindAudiencePackage.class)
    public ResponseData bindAudiencePackage(@RequestBody BindAudiencePackageRequest bindAudiencePackageRequest) {
        return iOceanengineToolService.bindAudiencePackage(bindAudiencePackageRequest);
    }

    @PostMapping("/unbindAudiencePackage")
    @ApiOperation(value = "定向包解绑", response = OceanengineUnBindAudiencePackage.class)
    public ResponseData unbindAudiencePackage(@RequestBody UnBindAudiencePackageRequest bindAudiencePackageRequest) {
        return iOceanengineToolService.unbindAudiencePackage(bindAudiencePackageRequest);
    }

    @PostMapping("/getIndustry")
    @ApiOperation(value = "获取行业列表", response = OceanengineGetIndustry.class)
    public ResponseData getIndustry(@RequestBody GetIndustryPackageRequest getIndustryPackageRequest) {
//        OceanengineGetIndustry result =null;
//        getIndustryPackageRequest.setLevel(1);
//        while (getIndustryPackageRequest.getLevel() < 4) {
//            OceanengineGetIndustry industry = iOceanengineToolService.getIndustry(getIndustryPackageRequest);
//            switch (getIndustryPackageRequest.getLevel()){
//                case 1:
//                    result=industry;
//                    break;
//                case 2:
//                    result
//                    break;
//                case 3:
//                    break;
//            }
//            getIndustryPackageRequest.setLevel(getIndustryPackageRequest.getLevel() + 1);

//        }

        return new ResponseData(ResponseData.Result.SUCCESS, iOceanengineToolService.getIndustry(getIndustryPackageRequest));
    }

    @PostMapping("/getProceduralPackage")
    @ApiOperation(value = "查询程序化创意包", response = OceanengineGetProceduralPackage.class)
    public ResponseData getProceduralPackage(@RequestBody GetProceduralPackageRequest getIndustryPackageRequest) {
        return iOceanengineToolService.getProceduralPackage(getIndustryPackageRequest);
    }
    @PostMapping("/estimateAudience")
    @ApiOperation(value = "查询受众预估结果--覆蓋量", response = OceanengineEstimateAudience.class)
    public ResponseData estimateAudience(@RequestBody EstimateAudienceRequest estimateAudienceRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanengineToolService.estimateAudience(estimateAudienceRequest));
    }

    @PostMapping("/suggestBid")
    @ApiOperation(value = "建议日预算及预期成本", response = OceanengineSuggestBid.class)
    public ResponseData suggestBid(@RequestBody SuggestBidRequest suggestBidRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanengineToolService.suggestBid(suggestBidRequest));
    }

    @PostMapping("/ad_stat_extra_info")
    @ApiOperation(value = "查询广告计划学习期状态", response = OceanengineAdStatExtraInfo.class)
    public ResponseData ad_stat_extra_info(@RequestBody AdStatExtraInfoRequest suggestBidRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanengineToolService.ad_stat_extra_info(suggestBidRequest));
    }

    @PostMapping("/getCreativeWord")
    @ApiOperation(value = "查询动态创意词包", response = OceanengineCreativeWord.class)
    public ResponseData getCreativeWord(@RequestBody CreativeWordRequest creativeWordRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanengineToolService.getCreativeWord(creativeWordRequest));
    }

//    @PostMapping("/uploadFileImage")
//    @ApiOperation(value = "上传图片素材",response = OceanengineUploadFileImage.class)
//    public ResponseData uploadFileImage(@RequestBody UploadFileImageRequest getLandingRequest){
//        return iOceanengineToolService.uploadFileImage(getLandingRequest);
//    }

    @PostMapping("/uploadFileImage")
    @ApiOperation(value = "上传图片素材", response = OceanengineUploadFileImage.class)
    public ResponseData uploadFileImage(@RequestParam("advertiser_id") @ApiParam(value = "广告主ID", required = true) Long advertiser_id,
                                        @RequestParam(value = "upload_type") @ApiParam(value = "图片上传方式\\n\" +\n" +
                                                "            \"默认值：\\\"UPLOAD_BY_FILE\\\"\\n\" +\n" +
                                                "            \"允许值：\\\"UPLOAD_BY_FILE\\\"\\\"UPLOAD_BY_URL\\\"") String upload_type,
                                        @RequestParam(value = "image_signature", required = false) @ApiParam(value = "图片的md5值(用于服务端校验)，upload_type为\"UPLOAD_BY_FILE\"必填") String image_signature,
                                        @RequestParam(value = "image_url", required = false) @ApiParam(value = "图片url地址，如http://xxx.xxx，upload_type为\"UPLOAD_BY_URL\"必填") String image_url,
                                        @RequestParam(value = "filename", required = false) @ApiParam(value = "素材的文件名，可自定义素材名，不传择默认取文件名，最长255个字符\\n\" +\n" +
                                                "            \"注：若同一素材已进行上传，重新上传不会改名") String filename,
                                        @RequestParam(value = "file", required = false) @ApiParam(value = "图片文件,upload_type为\\\"UPLOAD_BY_FILE\\\"必填\\n\" +\n" +
                                                "            \"格式: jpg，jpeg,png,bmp,gif, 大小1M内") MultipartFile file) {

        UploadFileImageRequest uploadFileImageRequest = new UploadFileImageRequest(advertiser_id, upload_type, image_signature, image_url, filename, file);
        return iOceanengineToolService.uploadFileImage(uploadFileImageRequest);
    }

//    @PostMapping("/uploadFileVideo")
//    @ApiOperation(value = "上传视频素材",response = OceanengineUploadFileVideo.class)
//    public ResponseData uploadFileVideo(@RequestBody UploadFileVideoRequest uploadFileVideoRequest){
//        return iOceanengineToolService.uploadFileVideo(uploadFileVideoRequest);
//    }

    @PostMapping("/uploadFileVideo")
    @ApiOperation(value = "上传视频素材", response = OceanengineUploadFileVideo.class)
    public ResponseData uploadFileVideo(@RequestParam("advertiser_id") @ApiParam(value = "广告主ID", required = true) Long advertiser_id,
                                        @RequestParam(value = "video_signature") @ApiParam(value = "视频的md5值(用于服务端校验)", required = true) String video_signature,
                                        @RequestParam(value = "filename", required = false) @ApiParam(value = "素材的文件名，可自定义素材名，不传择默认取文件名，最长255个字符\\n注：若同一素材已进行上传，重新上传不会改名") String filename,
                                        @RequestParam("file") @ApiParam(value = "视频文件,格式mp4、mpeg、3gp、avi（10s超时限制）", required = true) MultipartFile file) {

        UploadFileVideoRequest uploadFileVideoRequest = new UploadFileVideoRequest(advertiser_id, video_signature, filename, file);
        return iOceanengineToolService.uploadFileVideo(uploadFileVideoRequest);
    }

    @PostMapping("/uploadFileScrapVideo")
    @ApiOperation(value = "上传视频碎片素材", response = OceanengineUploadFileVideo.class)
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "content-type", value = "multipart/form-data", required = true) })
    public ResponseData uploadFileScrapVideo(@RequestParam("advertiser_id") @ApiParam(value = "广告主ID", required = true) Long advertiser_id,
                                             @RequestParam(value = "count",required = false) @ApiParam(value = "要生成计划的条数") Long count,
                                        @RequestParam("files1") @ApiParam(value = "视频文件,格式mp4、mpeg、3gp、avi（10s超时限制）", required = true) MultipartFile[] files1,
                                             @RequestParam("files2") @ApiParam(value = "视频文件,格式mp4、mpeg、3gp、avi（10s超时限制）", required = true) MultipartFile[] files2,
                                             @RequestParam("files3") @ApiParam(value = "视频文件,格式mp4、mpeg、3gp、avi（10s超时限制）", required = true) MultipartFile[] files3,
                                             @RequestParam("files4") @ApiParam(value = "视频文件,格式mp4、mpeg、3gp、avi（10s超时限制）", required = true) MultipartFile[] files4,
                                             @RequestParam("files5") @ApiParam(value = "视频文件,格式mp4、mpeg、3gp、avi（10s超时限制）", required = true) MultipartFile[] files5) {

//        return iOceanengineToolService.uploadFileScrapVideo(advertiser_id,files1,files2,files3,files4,files5);
        return iOceanengineToolService.uploadFileScrapVideoWithAudio(advertiser_id,count,files1,files2,files3,files4,files5);
//        return iOceanengineToolService.uploadFileScrapVideoWithAudio(advertiser_id,50l,files1,files2,files3,files4,files5);
    }

    @PostMapping("/uploadFileScrapVideoWithAudio")
    @ApiOperation(value = "上传视频碎片素材带合成音乐", response = OceanengineUploadFileVideo.class)
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "content-type", value = "multipart/form-data", required = true) })
    public ResponseData uploadFileScrapVideoWithAudio(@RequestParam("advertiser_id") @ApiParam(value = "广告主ID", required = true) Long advertiser_id,
                                        @RequestParam("files1") @ApiParam(value = "视频文件,格式mp4、mpeg、3gp、avi（10s超时限制）", required = true) MultipartFile[] files1,
                                             @RequestParam("files2") @ApiParam(value = "视频文件,格式mp4、mpeg、3gp、avi（10s超时限制）", required = true) MultipartFile[] files2,
                                             @RequestParam("files3") @ApiParam(value = "视频文件,格式mp4、mpeg、3gp、avi（10s超时限制）", required = true) MultipartFile[] files3,
                                             @RequestParam("files4") @ApiParam(value = "视频文件,格式mp4、mpeg、3gp、avi（10s超时限制）", required = true) MultipartFile[] files4,
                                             @RequestParam("files5") @ApiParam(value = "视频文件,格式mp4、mpeg、3gp、avi（10s超时限制）", required = true) MultipartFile[] files5) {

        return iOceanengineToolService.uploadFileScrapVideoWithAudio(advertiser_id,3l,files1,files2,files3,files4,files5);
    }
}
